(function($){
  /**
   * Behavior or Slideshow which is made with jCarousel and Cycle
   */
  Drupal.behaviors.slideshow = {
    attach : function() {
      
      var rotator = jQuery('#Rotator-SlideShow');
        
      var posY = Math.random();
          posY = ( Math.ceil( posY * 200 ) ) * -1;
    
    
      function ken_burns_loop(el) {
        
        var xxx = (el.attr('height') - 200) * -1;
        
        if( el.data('dir')==undefined) {
          el.data('dir',xxx);
        } else {
          var dir = ( el.data('dir') == xxx) ? 0 : xxx;
          el.data('dir',dir);
        }
        
        var duration = el.attr('height') * 30;
        
        $(el)
          .animate({
            top: el.data('dir')
          }, duration, 'linear', function(){
            ken_burns_loop(el);
          });
      }
    
      rotator
        .find('.slideshow')
          .cycle({
            fx                  :  'fade',
            pager               :  '#Rotator-SlideShow .carousel',
            pagerAnchorBuilder  :  function(idx, slide) {
              return '#Rotator-SlideShow .carousel li:eq(' + idx + ') a';
            },
            before : function() {
              
            },
            after : function() {
              var img = $(this).find('a').find('img');
                  //img.stop();
            }
          })
          .end()
        .find('.carousel')
          .jcarousel({visible:4});
        
        rotator.find('.slide').each(function(){
          var img = $(this).find('a').find('img');
              ken_burns_loop(img);
        }); 
        
        
    }
  };
}(jQuery));